package com.example.consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.TextMessage;

@Component
public class QueueMessageListener {

    private Queue testQueue;

    @Autowired
    public void setTestQueue(Queue testQueue) {
        System.out.println("注入testQueue:" + testQueue);
        this.testQueue = testQueue;
    }

    @JmsListener(destination = "#{testQueue.queueName}")
    public void onMessage(TextMessage message) throws JMSException {
        System.out.println("QueueMessageListener收到queue消息：" + message.getText());
    }

}
